package com.example.ddz.framework.impl;

import android.graphics.Point;

import com.example.ddz.framework.ButtonActionListener;
import com.example.ddz.framework.IGraphics;
import com.example.ddz.framework.IInput;
import com.example.ddz.framework.IPixmap;

public class RButton {
	  public static final int BUTTON_CALL = 8;
	  public static final int BUTTON_EXIT = 9;
	  public static final int BUTTON_FOLD = 1;
	  public static final int BUTTON_GET_POINTS = 12;
	  public static final int BUTTON_KEEPER = 11;
	  public static final int BUTTON_MUSIC_OFF = 14;
	  public static final int BUTTON_MUSIC_ON = 13;
	  public static final int BUTTON_NEXT = 10;
	  public static final int BUTTON_ONE = 2;
	  public static final int BUTTON_PASS = 5;
	  public static final int BUTTON_RECHOOSE = 6;
	  public static final int BUTTON_THREE = 4;
	  public static final int BUTTON_TIP = 7;
	  public static final int BUTTON_TWO = 3;
	  private ButtonActionListener btnActionListener;
	  private IPixmap[] btnImgs;
	  public int btnKind;
	  private IGraphics g;
	  private boolean isPressed;
	  public boolean isVisible = false;
	  private IPixmap strImgs;
	  private boolean triggerAfterDown;
	  private int x;
	  private int y;

	  public RButton(IGraphics paramGraphics, IPixmap[] paramArrayOfPixmap, ButtonActionListener paramButtonActionListener, int paramInt1, int paramInt2, int paramInt3, boolean paramBoolean)
	  {
		  IPixmap[] arrayOfPixmap = new IPixmap[2];
	    this.btnImgs = arrayOfPixmap;
	    this.strImgs = null;
	    this.isPressed = false;
	    this.triggerAfterDown = true;
	    this.btnActionListener = null;
	    this.g = paramGraphics;
	    this.btnImgs = paramArrayOfPixmap;
	    this.btnActionListener = paramButtonActionListener;
	    this.btnKind = paramInt1;
	    this.x = paramInt2;
	    this.y = paramInt3;
	    this.triggerAfterDown = paramBoolean;
	  }

	  public RButton(IGraphics paramGraphics, IPixmap[] paramArrayOfPixmap, IPixmap paramPixmap, ButtonActionListener paramButtonActionListener, int paramInt1, int paramInt2, int paramInt3, boolean paramBoolean)
	  {
		  IPixmap[] arrayOfPixmap = new IPixmap[2];
	    this.btnImgs = arrayOfPixmap;
	    this.strImgs = null;
	    this.isPressed = false;
	    this.triggerAfterDown = true;
	    this.btnActionListener = null;
	    this.g = paramGraphics;
	    this.btnImgs = paramArrayOfPixmap;
	    this.strImgs = paramPixmap;
	    this.btnActionListener = paramButtonActionListener;
	    this.btnKind = paramInt1;
	    this.x = paramInt2;
	    this.y = paramInt3;
	    this.triggerAfterDown = paramBoolean;
	  }

	  private boolean inBounds(IInput.TouchEvent paramTouchEvent)
	  {
		  IPixmap localPixmap;
	    if (this.btnImgs[0] == 0)
	    {
	      localPixmap = this.btnImgs[1];
	      int i = localPixmap.getRawWidth();
	      int j = localPixmap.getRawHeight();
	      int k = paramTouchEvent.x;
	      int m = this.x;
	      if (k <= m)
	        break label132;
	      int n = paramTouchEvent.x;
	      int i1 = this.x + i - 1;
	      if (n >= i1)
	        break label132;
	      int i2 = paramTouchEvent.y;
	      int i3 = this.y;
	      if (i2 <= i3)
	        break label132;
	      int i4 = paramTouchEvent.y;
	      int i5 = this.y + j - 1;
	      if (i4 >= i5)
	        break label132;
	    }
	    label132: for (int i6 = 1; ; i6 = 0)
	    {
	      return i6;
	      localPixmap = this.btnImgs[0];
	      break;
	    }
	  }

	  public void drawMe(IGraphics paramGraphics)
	  {
	    if (this.btnImgs.length > 0)
	    {
	      if (!this.isPressed)
	        break label147;
	      if (this.btnImgs[1] != 0)
	        break label112;
	      Pixmap localPixmap1 = this.btnImgs[0];
	      int i = this.x;
	      int j = this.y;
	      paramGraphics.drawPixmap(localPixmap1, i, j);
	    }
	    while (true)
	    {
	      if (this.strImgs != null)
	      {
	    	  IPixmap localPixmap2 = this.strImgs;
	    	  IPixmap localPixmap3 = this.btnImgs[0];
	        float f1 = this.x;
	        float f2 = this.y;
	        Point localPoint = paramGraphics.getCenter(localPixmap3, f1, f2);
	        paramGraphics.drawPixmapInParentCenter(localPixmap2, localPoint);
	      }
	      return;
	      label112: IPixmap localPixmap4 = this.btnImgs[1];
	      int k = this.x;
	      int m = this.y;
	      paramGraphics.drawPixmap(localPixmap4, k, m);
	      continue;
	      label147: IPixmap localPixmap5 = this.btnImgs[0];
	      int n = this.x;
	      int i1 = this.y;
	      paramGraphics.drawPixmap(localPixmap5, n, i1);
	    }
	  }

	  public IPixmap[] getBtnImgs()
	  {
	    return this.btnImgs;
	  }

	  public boolean onTouch(IInput.TouchEvent paramTouchEvent)
	  {
	    int i;
	    if (inBounds(paramTouchEvent))
	    {
	      i = paramTouchEvent.type;
	      if (this.triggerAfterDown)
	        if ((i == 0) || (i == 2))
	          this.isPressed = true;
	    }
	    for (int j = 1; ; j = 0)
	    {
	      return j;
	      if ((i != 1) || (this.btnActionListener == null))
	        break;
	      this.isPressed = false;
	      this.btnActionListener.performAction(this);
	      break;
	      if (i == 0)
	      {
	        this.isPressed = true;
	        if (this.btnActionListener == null)
	          break;
	        this.btnActionListener.performAction(this);
	        break;
	      }
	      if (i != 1)
	        break;
	      this.isPressed = false;
	      break;
	      this.isPressed = false;
	    }
	  }

	  public void setActionListener(ButtonActionListener paramButtonActionListener)
	  {
	    this.btnActionListener = paramButtonActionListener;
	  }

	  public void setBtnImgs(IPixmap[] paramArrayOfPixmap)
	  {
	    this.btnImgs = paramArrayOfPixmap;
	  }
}
